<?php
include_once ("function.php");
require_once ('page.class.php'); // 分页类
mssql_select_db ( $mssql_database, $conn );
$id = $_GET ['id'];
$showrow = 15; // 一页显示的行数
$curpage = empty ( $_GET ['page'] ) ? 1 : $_GET ['page']; // 当前的页,还应该处理非数字的情况
$s1 = $_COOKIE ["s"] . ' ' . '00:00:00.000';
$e1 = $_COOKIE ["e"] . ' ' . '23:59:59.999';
$s = iconv("utf-8",'gb2312',"$s1");
$e = iconv("utf-8",'gb2312',"$e1");
switch ($id) {
	case cz :
		$url = "?page={page}&id=cz"; // 分页地址，如果有检索条件 ="?page={page}&q=".$_GET['q']
		// 省略了链接mysql的代码，测试时自行添加
		$sql = "select * from ST_SupplyFund where Supply_Date between '$s' and '$e'";
		$limit = ($curpage - 1) * $showrow;
		$total = mssql_num_rows ( mssql_query ( $sql ) ); // 记录总条数
		if (! empty ( $_GET ['page'] ) && $total != 0 && $curpage > ceil ( $total / $showrow ))
			$curpage = ceil ( $total_rows / $showrow ); // 当前页数大于最后页数，取最后一页
				                                            // 获取数据
		$sql2 = "with fy
as(
select top $showrow ID_KEY from ST_SupplyFund AS B where B.Supply_Date between '$s' and '$e' and B.ID_KEY not in(select top $limit ID_KEY from ST_SupplyFund where Supply_Date between '$s' and '$e')
)
select  ID_KEY,A.Person_ID,convert(char,Supply_Date,120) as time,Supply_Fund as Fund,Person_No,Person_Name,Card_No 
from ST_SupplyFund as A 
left join
ST_Person on A.Person_ID=ST_Person.Person_ID where A.ID_KEY in (select * from fy)";
		// $sq = iconv ( "utf-8", 'gbk', "$sql2" );
		// where ST_Person.Is_Del='False' 卡被停用
		$query = mssql_query ( $sql2 );
		break;
	case tk :
		$url = "?page={page}&id=tk"; 
		$sql = "select * from ST_TakeFund where Take_Date between '$s' and '$e'";
		$limit = ($curpage - 1) * $showrow;
		$total = mssql_num_rows ( mssql_query ( $sql ) ); // 记录总条数
		if (! empty ( $_GET ['page'] ) && $total != 0 && $curpage > ceil ( $total / $showrow ))
			$curpage = ceil ( $total_rows / $showrow ); // 当前页数大于最后页数，取最后一页
		// 获取数据
		$sql2 = "with fy
		as(
		select top $showrow ID_KEY from ST_TakeFund AS B where B.Take_Date between '$s' and '$e' and B.ID_KEY not in(select top $limit ID_KEY from ST_TakeFund where Take_Date between '$s' and '$e')
		)
		select  ID_KEY,A.Person_ID,convert(char,Take_Date,120) as time,Take_Fund as Fund,Person_No,Person_Name,Card_No
		from ST_TakeFund as A
		left join
		ST_Person on A.Person_ID=ST_Person.Person_ID where A.ID_KEY in (select * from fy)";
		$query = mssql_query ( $sql2 );
		break;
	case zs1 :
		$url = "?page={page}&id=zs1";
		$sql = "select * from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='1'";
		$limit = ($curpage - 1) * $showrow;
		$total = mssql_num_rows ( mssql_query ( $sql ) ); // 记录总条数
		if (! empty ( $_GET ['page'] ) && $total != 0 && $curpage > ceil ( $total / $showrow ))
			$curpage = ceil ( $total_rows / $showrow ); // 当前页数大于最后页数，取最后一页
		// 获取数据
		$sql2 = "with fy
		as(
		select top $showrow ID_KEY from ST_SupplyFund AS B where B.Supply_Date between '$s' and '$e' and B.Remark='1' and B.ID_KEY not in(select top $limit ID_KEY from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='1')
		)
		select  ID_KEY,A.Person_ID,convert(char,Supply_Date,120) as time,Supply_Fund as Fund,Person_No,Person_Name,Card_No
		from ST_SupplyFund as A
		left join
		ST_Person on A.Person_ID=ST_Person.Person_ID where A.ID_KEY in (select * from fy)";
		$query = mssql_query ( $sql2 );
		break;
	case zs2 :
		$url = "?page={page}&id=zs2";
		$sql = "select * from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='2'";
		$limit = ($curpage - 1) * $showrow;
		$total = mssql_num_rows ( mssql_query ( $sql ) ); // 记录总条数
		if (! empty ( $_GET ['page'] ) && $total != 0 && $curpage > ceil ( $total / $showrow ))
			$curpage = ceil ( $total_rows / $showrow ); // 当前页数大于最后页数，取最后一页
		// 获取数据
		$sql2 = "with fy
		as(
		select top $showrow ID_KEY from ST_SupplyFund AS B where B.Supply_Date between '$s' and '$e' and B.Remark='2' and B.ID_KEY not in(select top $limit ID_KEY from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='2')
		)
		select  ID_KEY,A.Person_ID,convert(char,Supply_Date,120) as time,Supply_Fund as Fund,Person_No,Person_Name,Card_No
		from ST_SupplyFund as A
		left join
		ST_Person on A.Person_ID=ST_Person.Person_ID where A.ID_KEY in (select * from fy)";
		$query = mssql_query ( $sql2 );
		break;
		case zs3 :
			$url = "?page={page}&id=zs3";
			$sql = "select * from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='3'";
			$limit = ($curpage - 1) * $showrow;
			$total = mssql_num_rows ( mssql_query ( $sql ) ); // 记录总条数
			if (! empty ( $_GET ['page'] ) && $total != 0 && $curpage > ceil ( $total / $showrow ))
				$curpage = ceil ( $total_rows / $showrow ); // 当前页数大于最后页数，取最后一页
			// 获取数据
			$sql2 = "with fy
			as(
			select top $showrow ID_KEY from ST_SupplyFund AS B where B.Supply_Date between '$s' and '$e' and B.Remark='3' and B.ID_KEY not in(select top $limit ID_KEY from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='3')
			)
			select  ID_KEY,A.Person_ID,convert(char,Supply_Date,120) as time,Supply_Fund as Fund,Person_No,Person_Name,Card_No
			from ST_SupplyFund as A
			left join
			ST_Person on A.Person_ID=ST_Person.Person_ID where A.ID_KEY in (select * from fy)";
			$query = mssql_query ( $sql2 );
			break;
		case zs4 :
				$url = "?page={page}&id=zs4";
				$sql = "select * from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='4'";
				$limit = ($curpage - 1) * $showrow;
				$total = mssql_num_rows ( mssql_query ( $sql ) ); // 记录总条数
				if (! empty ( $_GET ['page'] ) && $total != 0 && $curpage > ceil ( $total / $showrow ))
					$curpage = ceil ( $total_rows / $showrow ); // 当前页数大于最后页数，取最后一页
				// 获取数据
				$sql2 = "with fy
				as(
				select top $showrow ID_KEY from ST_SupplyFund AS B where B.Supply_Date between '$s' and '$e' and B.Remark='4' and B.ID_KEY not in(select top $limit ID_KEY from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='4')
				)
				select  ID_KEY,A.Person_ID,convert(char,Supply_Date,120) as time,Supply_Fund as Fund,Person_No,Person_Name,Card_No
				from ST_SupplyFund as A
				left join
				ST_Person on A.Person_ID=ST_Person.Person_ID where A.ID_KEY in (select * from fy)";
				$query = mssql_query ( $sql2 );
				break;
			case zs5 :
					$url = "?page={page}&id=zs5";
					$sql = "select * from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='5'";
					$limit = ($curpage - 1) * $showrow;
					$total = mssql_num_rows ( mssql_query ( $sql ) ); // 记录总条数
					if (! empty ( $_GET ['page'] ) && $total != 0 && $curpage > ceil ( $total / $showrow ))
						$curpage = ceil ( $total_rows / $showrow ); // 当前页数大于最后页数，取最后一页
					// 获取数据
					$sql2 = "with fy
					as(
					select top $showrow ID_KEY from ST_SupplyFund AS B where B.Supply_Date between '$s' and '$e' and B.Remark='5' and B.ID_KEY not in(select top $limit ID_KEY from ST_SupplyFund where Supply_Date between '$s' and '$e' and Remark='5')
					)
					select  ID_KEY,A.Person_ID,convert(char,Supply_Date,120) as time,Supply_Fund as Fund,Person_No,Person_Name,Card_No
					from ST_SupplyFund as A
					left join
					ST_Person on A.Person_ID=ST_Person.Person_ID where A.ID_KEY in (select * from fy)";
					$query = mssql_query ( $sql2 );
					break;
}
$i = 1;
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>尚客优品储值卡管理系统</title>
<link rel="stylesheet" type="text/css" href="css/common.css" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<style>
#list {
	width: 100%;
}

#list {
	border-collapse: collapse;
	border: 1px solid #ddd;
}

#list th {
	font-weight: normal;
	font-size: 15px;
	text-align: center;
	background: url(../images/tab-thbg.png) #f9f9f9 0 bottom repeat-x;
}

#list th, #list td {
	padding: 5px;
	border-bottom: 1px solid #ddd;
	border-right: 1px solid #e1e1e1;
	text-align: center;
}

#list tr {
	line-height: 35px;
}

#list th.tc, #list td.tc {
	text-align: center;
}

#list tr:nth-child(odd) {
	background: #f9f9f9;
}

#list tr:hover {
	background: #f1f1f1;
}

#list tr.even-tr {
	background: #e9fff2;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">
p {
	margin: 0
}

#page {
	height: 40px;
	padding: 20px 0px;
}

#page a {
	display: block;
	float: left;
	margin-right: 10px;
	padding: 2px 12px;
	height: 24px;
	border: 1px #cccccc solid;
	background: #fff;
	text-decoration: none;
	color: #808080;
	font-size: 12px;
	line-height: 24px;
}

#page a:hover {
	color: #077ee3;
	border: 1px #077ee3 solid;
}

#page a.cur {
	border: none;
	background: #077ee3;
	color: #fff;
}

#page p {
	float: left;
	padding: 2px 12px;
	font-size: 12px;
	height: 24px;
	line-height: 24px;
	color: #bbb;
	border: 1px #ccc solid;
	background: #fcfcfc;
	margin-right: 8px;
}

#page p.pageRemark {
	border-style: none;
	background: none;
	margin-right: 0px;
	padding: 4px 0px;
	color: #666;
}

#page p.pageRemark b {
	color: red;
}

#page p.pageEllipsis {
	border-style: none;
	background: none;
	padding: 4px 0px;
	color: #808080;
}

.dates li {
	font-size: 14px;
	margin: 20px 0
}

.dates li span {
	float: right
}
</style>
</head>
<body>
	<div class="container clearfix">
		<div class="sidebar-wrap">
			<div class="sidebar-title">
				<h1>尚客优品</h1>
			</div>
			<div class="sidebar-content">
				<ul class="sidebar-list">
					<li><a href="#"><i class="icon-font">&#xe003;</i>常用操作</a>
						<ul class="sub-menu">
							<li><a href="index.php"><i class="icon-font">&#xe008;</i>收银报表</a></li>
							<li><a href="mx.php"><i class="icon-font">&#xe005;</i>收支明细</a></li>
							<li><a href="kmx.php"><i class="icon-font">&#xe006;</i>交易明细</a></li>
						</ul></li>

				</ul>
			</div>
		</div>
		<!--/sidebar-->
		<div class="main-wrap">
			<div class="crumb-wrap">
				<div class="crumb-list">
					<i class="icon-font"></i><a href="index.php" color="#white">首页</a><span
						class="crumb-step">&gt;</span><span class="crumb-name"><?php 
						switch($id){
							case cz:
								echo 充值明细 ;
								break;
							case tk:
								echo 退款明细;
								break;
							case zs1:
								echo 满两百赠送明细;
								break;
							case zs2:
								echo 满三百赠送明细;
								break;		
								case zs3:
									echo 满五百赠送明细;
									break;
									case zs4:
										echo 其他赠送明细;
										break;
										case zs5:
											echo 美团明细;
											break;
						}
						?></span>
				</div>
			</div>
			<!--/sidebar-->
			<div id="main">



				<div class="result-content" id="list">
					<table>

						<tr>

							<th>行号</th>
							<th>卡号</th>
							<th>人员编号</th>
							<th>持卡人</th>
							<th>日期</th>
							<th>金额</th>


						</tr>
                   <?php
																			while ( $rst = mssql_fetch_assoc ( $query ) ) {
																				?>
                   <tr>
							<td><?php echo $i;$i++;?></td>
							<td><?php echo  iconv ( 'gbk', 'utf-8', $rst ['Card_No'] );?></td>
							<td><?php echo  iconv ( 'gbk', 'utf-8', $rst ['Person_No'] );?></td>
							<td><?php echo  iconv ( 'gbk', 'utf-8', $rst ['Person_Name'] );?></td>
							<td><?php
																				
																				echo $rst ['time'];
																				?></td>
							<td><?php echo  iconv ( 'gbk', 'utf-8', $rst ['Fund'] );?></td>

						</tr>
                   
                     <?php
																			}
																			
																			?>
                    </table>

				</div>

				<div class="showPage">
                    <?php
																				if ($total > $showrow) { // 总记录数大于每页显示数，显示分页
																					$page = new page ( $total, $showrow, $curpage, $url, 2 );
																					echo $page->myde_write ();
																				}
																				?>
                </div>
				<!--/main-->

			</div>

</body>
</html>









